﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Adams.Admin.Business.Console
{
    public static class Profile
    {
        public static Adams.Admin.DataTransfer.Console.Profile.PageLoad PageLoad(int userId)
        {
            return DataAccess.Console.Profile.PageLoad(userId);
        }

        public static DataTransfer.FormOutput SaveProfile(DataTransfer.Console.Profile.FormInput input)
        {
            var output = Validation.PerformBasicValidation(input);

            if (output.IsValid)
            {
                var userinfo = DataAccess.Console.CreateUser.GetUserInfo(input.ID, input.Email);
                if (input.ID > 0)
                {
                    if (!Shared.Str.IsEqual(input.Email, userinfo.Email))
                    {
                        if (userinfo.Exists)
                        {
                            output.InvalidFields.Add(new DataTransfer.InvalidField()
                            {
                                Name = "Email",
                                Code = 4
                            });
                        }
                    }
                }

                if (output.IsValid)
                {
                    DataAccess.Console.Profile.SaveProfile(input);
                    output.IsSaved = true;
                }
            }

            return output;
        }
    }
}
